<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
//$this->model('task')->test();
$return['status']=$this->member_status;
$tabs=array(
	array('op'=>'list','title'=>'全部用户'),
	array('op'=>'edit','title'=>'编辑用户'),
); 
if($_RQ['op']=='list'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['isvip'])){
		$params['isvip']=intval($_RQ['isvip']);
		$return['params']['isvip']=intval($_RQ['isvip']);
	}
	if($_RQ['mid']){
		$params['mid']=$_RQ['mid'];
		$return['params']['mid']=$_RQ['mid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_kaoshi_member',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['member']['mobile']=$item['mobile']?:$item['member']['mobile'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'mid','title'=>'会员id','type'=>'string'),
			array('name'=>'member','title'=>'粉丝信息','type'=>'member'),
			array('name'=>'name','title'=>'真实姓名','type'=>'string'),
			array('name'=>'vipendtime','title'=>'VIP到期时间','type'=>'time'),
			array('name'=>'isvip','title'=>'已开通VIP','type'=>'radio','options'=>'isvip'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'modal','op'=>'setlevel','title'=>'设置等级'),
		)),
		'search'=>array(
			array('name'=>'isvip','width'=>15,'title'=>'已开通VIP','type'=>'radio','options'=>'isvip'),
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),

		)
	);
	$return['isvip']=array('未开通','已开通');
	$return['levels']=$this->getall('level',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['levels']['0']=array('id'=>'0','title'=>'默认等级');
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_kaoshi_member',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array('get_type'=>0);
	}
	$item['vipendtime']=date('Y-m-d H:i:s',$item['vipendtime']);
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回用户列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
						array(
							'title'=>'基本信息',
							'list'=>array(
								array('name'=>'name','title'=>'姓名','type'=>'string'),
								array('name'=>'code','title'=>'身份证号','type'=>'string'),
								array('name'=>'mobile','title'=>'手机号','type'=>'string'),
								array('name'=>'danwei','title'=>'单位','type'=>'string'),
								array('name'=>'vipendtime','title'=>'VIP到期时间','type'=>'time'),
								array('name'=>'isvip','title'=>'已开通VIP','type'=>'radio','options'=>'isvip'),
								array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
							)
						),
			
			)
	);
	$return['isvip']=array('未开通','已开通');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'name'=>($postdata['name']),
		'code'=>($postdata['code']),
		'mobile'=>($postdata['mobile']),
		'danwei'=>($postdata['danwei']),
		'isvip'=>intval($postdata['isvip']),
		'vipendtime'=>strtotime($postdata['vipendtime']),
		'status'=>intval($postdata['status']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_kaoshi_member',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_kaoshi_member',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='setlevel'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		$this->update('member',array('level_id'=>intval($post['level_id'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('设置成功！','','list');
	}
	$item=$this->get('member',array('id'=>intval($_RQ['id'])));
	if(!$item){
		exi('指定分销不存在！','error');
	}
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'设置等级',
		'edit'=>array(
			array('name'=>'level_id','title'=>'等级','type'=>'select','options'=>'levels'),
		),
	);
	$return['levels']=$this->getall('level',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['levels']['0']=array('id'=>'0','title'=>'默认等级');
	exi($return);
}